package com.coursehub.progress.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 学生资料学习进度实体类
 */
@Entity
@Table(name = "student_material")
@Data
@NoArgsConstructor
@AllArgsConstructor
@IdClass(StudentMaterialId.class)
public class StudentMaterial {
    
    /**
     * 学生用户ID
     */
    @Id
    @Column(name = "user_id", nullable = false, length = 100)
    private String userId;
    
    /**
     * 课程ID
     */
    @Id
    @Column(name = "course_id", nullable = false, length = 100)
    private String courseId;
    
    /**
     * 章节ID
     */
    @Id
    @Column(name = "chapter_id", nullable = false, length = 100)
    private String chapterId;
    
    /**
     * 资料ID
     */
    @Id
    @Column(name = "material_id", nullable = false, length = 100)
    private String materialId;
    
    /**
     * 是否学完
     */
    @Column(name = "is_finished", nullable = false)
    private Boolean isFinished = false;
    
    /**
     * 创建时间
     */
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    /**
     * 更新时间
     */
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
    
    /**
     * 完成时间
     */
    @Column(name = "finished_at")
    private LocalDateTime finishedAt;
    
    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
        updatedAt = LocalDateTime.now();
    }
    
    @PreUpdate
    protected void onUpdate() {
        updatedAt = LocalDateTime.now();
    }
}